package com.ruoyi.nongjt.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.nongjt.domain.pojo.NjtSupervisor;
import com.ruoyi.nongjt.mapper.NjtSupervisorMapper;
import com.ruoyi.nongjt.service.NjtSupervisorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class NjtSupervisorServiceImpl implements NjtSupervisorService {
    @Autowired
    private NjtSupervisorMapper njtSupervisorMapper;

    @Override
    public List<NjtSupervisor> getNjtSupervisorList(NjtSupervisor supervisor) {
        return njtSupervisorMapper.selectNjtSupervisorList(supervisor);
    }

    @Override
    public NjtSupervisor getSupervisorByPhone(String phone) {
        return njtSupervisorMapper.getSupervisorByPhone(phone);
    }

    @Override
    public int insertNjtSupervisor(NjtSupervisor supervisor) {
        supervisor.setCreateTime(new Date());
        supervisor.setUpdateTime(new Date());
        return njtSupervisorMapper.insertNjtSupervisor(supervisor);
    }
    @Override
    public int resetPasswordByPhone(String mobilePhone, String newPassword) {
        return njtSupervisorMapper.updatePasswordByPhone(mobilePhone, newPassword);
    }

    @Override
    public List<NjtSupervisor> selectSupervisorList(NjtSupervisor supervisor) {
        return njtSupervisorMapper.selectSupervisorList(supervisor);
    }

    @Override
    public int insertSupervisor(NjtSupervisor supervisor) {
        supervisor.setPassword(SecurityUtils.encryptPassword(supervisor.getPassword()));
        supervisor.setCreateTime(new Date());
        supervisor.setUpdateTime(new Date());
        return njtSupervisorMapper.insertSupervisor(supervisor);
    }

    @Override
    public int updateSupervisor(NjtSupervisor supervisor) {
        supervisor.setUpdateTime(new Date());
        return njtSupervisorMapper.updateSupervisor(supervisor);
    }

    @Override
    public int deleteSupervisorById(Long id) {
        return njtSupervisorMapper.deleteSupervisorById(id);
    }

    @Override
    public NjtSupervisor selectSupervisorById(Long id) {
        return njtSupervisorMapper.selectSupervisorById(id);
    }
}